<!DOCTYPE html>
<script src="../include.js"></script>
<script src="gamepad-helper.js"></script>
<script>
    asyncTest(async (done) => {
        const gamepad = internals.connectVirtualGamepad();
        await handleSDLInputEvents();
        listenForGamepadConnected();

        for (const button of gamepad.buttons) {
            println(`Before pressing button ${button}: ${getStringifiedGamepads()}`);
            gamepad.setButton(button, true);
            await handleSDLInputEvents();
            println(`After pressing button ${button}: ${getStringifiedGamepads()}`);
            gamepad.setButton(button, false);
            await handleSDLInputEvents();
            println(`After unpressed button: ${getStringifiedGamepads()}`);
        }

        listenForGamepadDisconnected();
        gamepad.disconnect();
        await handleSDLInputEvents();
        done();
    });
</script>
